//
//  MainViewController.swift
//  weibo
//
//  Created by xmg on 15/12/19.
//  Copyright © 2015年 xmg. All rights reserved.
//

import UIKit

class MainViewController :UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
        // 添加按钮
        tabBar.addSubview(ComposeButton)
        
        // 计算每个按钮的宽度
        let width = tabBar.bounds.width / CGFloat(childViewControllers.count)
        
        // 重新设置加号按钮的宽度
        ComposeButton.frame.size.width = width;
        
        // 取出加号按钮的frame
        let rect = ComposeButton.frame
        
        // 加号按钮的文字
        ComposeButton.frame = CGRectOffset(rect, width * 2, 0)
    }
    // 点击方法
    @objc private func composeBtnClick()
    {
        
    }
    
    // mark -- 懒加载
    private lazy var ComposeButton: UIButton = {
        // 0.创建按钮
        let btn = UIButton(imageName: "tabbar_compose_icon_add", backgroundImageName: "tabbar_compose_button")
        
        // 1. 添加监听点击事件
        btn.addTarget(self, action: Selector("composeBtnClick"), forControlEvents: UIControlEvents.TouchUpInside)
        
        return btn
    }()
}